package com.xzy.generic;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 带泛型的事件
 *
 * @author xzy.xiao
 * @date 2023/2/27  9:35
 */
class Main {
    public static void main(String[] args) throws InterruptedException {
        // 创建容器
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();

        // 注册事件监听器
        applicationContext.registerBean("genericEventListener1", GenericEventListener.class); // Note：事件会被所有相关监听器监听到
        applicationContext.registerBean("generictListener2", GenericEventListener.class);
        applicationContext.refresh();

        // 发布事件
        for (int i = 0; i < 3; i++) {
            GenericEventPublisher.sendUserInsertEvent(applicationContext);
            GenericEventPublisher.sendLoginInsertEvent(applicationContext);

            Thread.sleep(1000);
        }
    }
}
